package com.yunpuvip.sachet.rest.common.util;

import cn.hutool.core.util.ObjectUtil;
import com.yunpuvip.sachet.modular.util.cache.CacheKit;

/**
 * 用户获取短信验证码以及存储短信验证码
 * @ClassName VerifyCodeKit
 * @Description TODO
 * @Autor wushaohong
 * @Date 2018/11/16
 * @Version 1.0
 */
public class VerifyCodeKit {
    /**
     * 获取验证码
     * @param phoneNumber
     * @return
     */
    public  static String  getVerifyCode(String phoneNumber){

        return (String) CacheKit.get("verifyCode",phoneNumber);
    }

    /**
     * 存储验证码
     * @param phoneNumber
     * @param verifyCode
     */

    public static  void putVerifyCode(String phoneNumber,String verifyCode){
        CacheKit.put("verifyCode",phoneNumber,verifyCode);
    }

    /**
     * 校验短信验证码
     * @param phoneNumber
     * @param code
     * @return
     */
    public  static boolean checkVerifyCode(String phoneNumber,String code){
        String verifyCode = getVerifyCode(phoneNumber);
        System.err.println("userCode:"+code);
        System.err.println("serverCode:"+verifyCode);

        if(ObjectUtil.equal(code,verifyCode)){
            return false;
        }else if(ObjectUtil.equal(verifyCode,code)){
            return true;
        }
        return false;
    }

}
